<template>
  <!-- 面包屑导航 -->
  <div style="height: 6vh;background-color:#fff;padding:10px 20px;">
    <span style="line-height:60px;font-size:20px;">信息管理</span>
  </div>
  <div class="page-container">
    <!-- 主要内容区域 -->
    <p></p>
    <el-card class="main-card">
      <!-- 基本信息表单 -->
      <el-form :model="formData" label-width="120px">
        <el-form-item label="活动标题：">
          <el-input v-model="formData.title" placeholder="请输入活动" clearable />
        </el-form-item>

        <el-form-item label="营销方式：">
          <el-select v-model="formData.marketingType" placeholder="请选择营销列表" clearable>
            <el-option
                v-for="item in marketingTypes"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>

      <!-- 活动列表区域 -->
      <div class="section-title">活动列表</div>
      <div class="list-header">
        <span>编号：</span>
        <span>活动标题：</span>
      </div>

      <!-- 活动选择区域 -->
      <div class="activity-options">
        <el-button
            v-for="item in activityOptions"
            :key="item.value"
            :type="selectedActivity === item.value ? 'primary' : ''"
            @click="selectActivity(item.value)"
        >
          {{ item.label }}
        </el-button>
      </div>

      <!-- 新建活动按钮 -->
      <div class="action-buttons">
        <el-button type="primary" @click="showCreateDialog">新建活动</el-button>
      </div>
    </el-card>

    <!-- 新建活动弹窗 -->
    <el-dialog
        v-model="dialogVisible"
        title="新建活动"
        width="50%"
        :close-on-click-modal="false"
    >
      <el-form :model="newActivityForm" label-width="120px">
        <el-form-item label="活动时间：">
          <el-date-picker
              v-model="newActivityForm.timeRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item label="活动状态：">
          <el-select v-model="newActivityForm.status" placeholder="请选择活动状态">
            <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="confirmCreate">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

// 表单数据
const formData = reactive({
  title: '',
  marketingType: ''
})

// 营销方式选项
const marketingTypes = ref([
  { value: '1', label: '拼团' },
  { value: '2', label: '秒杀' },
  { value: '3', label: '返现' },
  { value: '4', label: '抽奖' }
])

// 活动选项
const activityOptions = ref([
  { value: 'group', label: '拼团' },
  { value: 'seckill', label: '秒杀' },
  { value: 'cashback', label: '返现' },
  { value: 'lottery', label: '抽奖' }
])

// 选中的活动类型
const selectedActivity = ref('')

// 新建活动弹窗相关
const dialogVisible = ref(false)
const newActivityForm = reactive({
  timeRange: [],
  status: ''
})

// 活动状态选项
const statusOptions = ref([
  { value: '1', label: '未开始' },
  { value: '2', label: '进行中' },
  { value: '3', label: '已结束' }
])

// 选择活动类型
const selectActivity = (type) => {
  selectedActivity.value = type
  formData.marketingType = type
}

// 显示新建活动弹窗
const showCreateDialog = () => {
  if (!selectedActivity.value) {
    ElMessage.warning('请先选择活动类型')
    return
  }
  dialogVisible.value = true
  // 重置表单
  Object.assign(newActivityForm, {
    timeRange: [],
    status: ''
  })
}

// 确认新建活动
const confirmCreate = () => {
  if (!newActivityForm.timeRange || newActivityForm.timeRange.length === 0) {
    ElMessage.warning('请选择活动时间')
    return
  }
  if (!newActivityForm.status) {
    ElMessage.warning('请选择活动状态')
    return
  }

  // 这里应该是提交表单的API调用
  ElMessage.success('活动创建成功')
  dialogVisible.value = false
}
</script>

<style scoped>
.page-container {
  padding: 20px;
}

.breadcrumb {
  margin-bottom: 20px;
}

.page-title {
  margin-bottom: 20px;
  font-size: 20px;
  font-weight: bold;
}

.main-card {
  margin-bottom: 20px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  margin: 20px 0 15px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.list-header {
  display: flex;
  margin-bottom: 15px;
  font-weight: bold;
}

.list-header span {
  margin-right: 20px;
}

.activity-options {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.action-buttons {
  margin-top: 20px;
  text-align: center;
}
</style>